package com.example.park.service.impl;

import com.example.common.utils.R;
import com.example.park.dao.ParkShareDao;
import com.example.park.dao.ParkingDao;
import com.example.park.entity.ParkShareEntity;
import com.example.park.entity.ParkingEntity;
import com.example.park.entityVO.ParkingDimVO;
import com.example.park.entityVO.ParkingVO;
import com.example.park.entityVO.WeiXinParking;
import com.example.park.service.ParkingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ParkingServiceImpl implements ParkingService {

    @Autowired
    private ParkingDao parkingDao;

    @Autowired
    private ParkShareDao parkShareDao;

    @Override
    public List<ParkingVO> queryVOByDim(ParkingDimVO vo) {
        return parkingDao.queryVOByDim(vo);
    }

    @Override
    public List<ParkingEntity> weiXinQuery(WeiXinParking weiXinParking) {
        return parkingDao.weiXinQuery(weiXinParking);
    }

    @Override
    public List<ParkingVO> queryVOByParam(ParkingVO vo) {
        return parkingDao.queryVOByParam(vo);
    }

    @Override
    public String bindParking(ParkingVO pe) {
        if (pe.getKey() == null) {
            return "标识码不能为空！";
        }
        ParkingEntity p = new ParkingEntity();
        p.setuId(pe.getuId());
        p.setId(pe.getId());
        pe.setuId(null);
        List<ParkingVO> vos = parkingDao.queryVOByParam(pe);
        if (vos.size() > 0) {
            if (parkingDao.update(p) > 0) {
                return "绑定成功！";
            }
        }
        return "绑定失败！";
    }

    @Override
    public boolean insert(ParkingEntity parkingEntity) {
        return parkingDao.insert(parkingEntity) > 0;
    }

    @Override
    public boolean update(ParkingEntity parkingEntity) {
        return parkingDao.update(parkingEntity) > 0;
    }

    @Override
    public boolean delete(Integer id) {
        return parkingDao.delete(id) > 0;
    }

    @Override
    public boolean unbind(Integer id) {
        return parkingDao.unbind(id) > 0;
    }
}
